<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
	<style>
		body, input{
			font-family: Calibri, Arial;
		}
		table#contact {
			border-collapse: collapse;
			width:550px;
		}
		th {
			height: 40px;
			background-color: #ffee55;
		}
	</style>
	<title>Categoria Manager - Project Live!</title>
</head>
<body>
	<div id="insDiv" class="insDiv">
		<h1> 
			<img class="insDivImg insDivImgOpen" src="images/arr-open.png"/> 
			<span>Inserimento Categoria</span>
		</h1>
	</div>	
	<s:actionerror/>
	<div id="insBox" class="insBox">
		<s:form action="addCategoria" method="post" theme="simple">
			<s:hidden name="id" value="%{id}"/>
			<table>
				<tr>
					<td><s:label value="Nome:"/></td>
					<td><s:textfield name="categoria.nome"/></td>
					<td><s:label value="Descrizione:"/></td>
					<td><s:textfield name="categoria.descrizione"/></td>
					<td><s:submit value="Salva Categoria" align="center"/></td>
				</tr>
			</table>		
		</s:form>
	</div>	

	</br></br>
	<h2>Lista Categorie</h2>
	<table id="rounded-corner">
		<tr>
			<th class="width5 textCenter">#</th>
			<th class="width40 textLeft">Nome</th>
			<th class="width40 textLeft">Descrizione</th>
			<th class="width10 textCenter">Modifica</th>
			<th class="width10 textCenter">Elimina</th>
		</tr>
		<s:iterator value="categorie">
		<tr>
			<td class="textCenter">
				<s:property value="id"/>
			</td>
			<td class="textLeft">
				<s:property value="nome"/>
			</td>
			<td class="textLeft">
				<s:property value="descrizione"/>
			</td>	
			<td>
				<s:form theme="simple">
					<s:if test="%{id==0}">
						<s:submit action="editCategoria" value="Modifica" disabled="true"/>
					</s:if>
					<s:else>
						<s:submit action="editCategoria" value="Modifica"/>
				        <s:hidden name="id" value="%{id}"/>
					</s:else>
			    </s:form>
			</td>
			<td>
				<s:form theme="simple">
					<s:if test="%{id==0}">
						<s:submit action="deleteCategoria" value="Rimuovi" disabled="true"/>
					</s:if>
					<s:else>
						<s:submit action="deleteCategoria" value="Rimuovi"
							onclick="return confirm('Sei sicuro di voler cancellare la categoria e tutte le sottocategorie?');"/>
				        <s:hidden name="id" value="%{id}"/>
					</s:else>
			    </s:form>
			</td>
		</tr>	
		</s:iterator>
	</table>
</body>
</html>